package v1

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// @Summary 测试
// @Produce  json
// @Param id param int true "ID"
// @Param name query string true "ID"
// @Param state query int false "State"
// @Param modified_by query string true "ModifiedBy"
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
// @Router /api/v1/test  [get]
func TestApi(c *gin.Context) {

	c.JSON(200, gin.H{
		"msg": "apiV1",
	})

}

//upload file
func Upload(c *gin.Context) {
	c.Request.ParseMultipartForm(8 << 20)
	file, err := c.FormFile("file")
	if err != nil {
		//logging.Println(err)
		c.JSON(http.StatusBadRequest, gin.H{"data": "fail"})
		return
	}
	fileName := file.Filename
	fileSize := file.Size
	if fileName == "" || fileSize == 0 {
		//logging.Println("请上传文件")
		c.JSON(http.StatusBadRequest, gin.H{"data": "fail"})
		return
	}
	if err := c.SaveUploadedFile(file, "./logs/"+file.Filename); err != nil {
		//logging.Println(err)
		c.JSON(http.StatusBadRequest, gin.H{"data": "fail"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"data": "ok"})

}
